package com.yicong.ants.manager.config;

import android.content.Context;
import android.view.View;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;

import com.cchao.simplelib.Const;
import com.cchao.simplelib.core.Router;
import com.cchao.simplelib.core.UiHelper;
import com.cchao.simplelib.view.itemdecoration.GridOffsetsItemDecoration;
import com.yicong.ants.Constants;
import com.yicong.ants.R;
import com.yicong.ants.manager.AppHelper;
import com.yicong.ants.ui.find.YcWebViewActivity;
import com.yicong.ants.view.GridOffsetItemDecoration;

import org.apache.commons.lang3.tuple.Triple;

import java.util.ArrayList;
import java.util.List;

/**
 * 配置父类，子类继承它，并选择性复写
 *
 * @author cchao
 * @version 2019-07-03.
 */
public class ConfigParent {
    public static ConfigParent mInstance = new ConfigParent();

    public static String mGasAppId = "yicong";
    public static String mGasAppSecret = "youbei6";
    public static boolean mCheckPrivacy = false;

    // <editor-fold desc="tourism">
    public static boolean mTourismSearchBar = false;
    // 付费景区
    public static boolean mTourismChargeAble = false;
    // 入口显示 列数
    public static int mTourismPortalGridNum = 3;
    // 推荐景区的 列数
    public static int mTourismScenicRecGridNum = 2;
    // 推荐景区的 样式
    public static int mTourismScenicStyle = R.layout.tourism_rec_item;
    // 热销商品的 样式
    public static int mTourismMallStyle = R.layout.tourism_mall_item;

    // 景区推荐列表 分割线样式
    public static RecyclerView.ItemDecoration mTourismRecItemDecoration =
        new GridOffsetItemDecoration(GridOffsetsItemDecoration.GRID_OFFSETS_VERTICAL)
            .setHideFirstRowTopOffset(true)
            .setVerticalItemOffsets(UiHelper.dp2px(8))
            .setHorizontalItemOffsets(UiHelper.dp2px(8));

    public static List<Triple<Integer, String, RouterCallback>> mTourismPortal = new ArrayList<>();
    public static List<Triple<Integer, String, RouterCallback>> mPresentPortal = new ArrayList<>();
    // </editor-fold>

    // <editor-fold desc="scenic">
    public static int mScenicShowPriceVisible = View.GONE;
    public static int mScenicShowAddedItems = View.VISIBLE;
// <editor-fold desc="mine">

    // <editor-fold>

    public static boolean mMineSignAble = false;
    public static boolean mMeShowProtocol = true;
    public static int mMePortalGridNum = 3;
    public static int mMePortalQrLayout = R.layout.my_tourist_qrcode;
    // </editor-fold>

    public static int mCardImageVisible = View.VISIBLE;
    public static int mDebugVisible = AppHelper.isDebug() ? View.VISIBLE : View.GONE;

    // <editor-fold desc="global">

    public static boolean mGlobalCollectFeature = true;
    // 引导界面
    public static boolean mGlobalStartGuideAble = false;
    // 启动页的布局
    public static String mGlobalApi = Constants.Api_Product;
    //    public static String mVideo = "http://ycvideo.cn.utools.club";
    public static String mVideo = "http://video.dev.yctourism.com";
    public static String mApiHotel = "http://hotel.dev.yctourism.com";
    public static String mApiLine =  AppHelper.isTestEnv() ? Constants.Api_Line_Dev : Constants.Api_Line;

    // </editor-fold>

    // region home
    public static List<Triple<Integer, String, Fragment>> mHomeFragment = new ArrayList<>();
    //endregion

    public static RouterCallback getLoginRoute(Class activity, boolean needLogin) {
        return context -> {
            if (needLogin) {
                Router.turnTo(context, activity).checkLogin(true).start();
            } else {
                Router.turnTo(context, activity).start();
            }
        };
    }

    public static void routeAtyCheckLogin(Context context, Class activity) {
        Router.turnTo(context, activity).checkLogin(true).start();
    }

    public static RouterCallback getLoginRoute(Class activity) {
        return context -> {
            Router.turnTo(context, activity).checkLogin(true).start();
        };
    }

    public static RouterCallback getRoute(Class activity) {
        return context -> {
            Router.turnTo(context, activity).start();
        };
    }

    public static RouterCallback getRouteWeb(String url, String title, boolean needLogin) {
        return context -> {
            //
            Router.turnTo(context, YcWebViewActivity.class)
                .putExtra(Const.Extra.Web_View_Url, url)
                .putExtra(Const.Extra.Web_View_Tile, title)
                .checkLogin(needLogin)
                .start();
        };
    }

    public static RouterCallback getBindRout(Class activity) {
        return getBindRout(activity, true);
    }

    public static RouterCallback getBindRout(Class activity, boolean needBind) {
        return context -> {
            if (needBind) {
                Router.turnTo(context, activity).checkStatus(Constants.Rout.bind_card, true).start();
            } else {
                Router.turnTo(context, activity).start();
            }
        };
    }

    public static ConfigParent get() {
        return mInstance;
    }

    public interface RouterCallback {
        void onCallBack(Context context);
    }
}
